/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2012-06-10 18:46:02                          */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"Autorzy <-> Ksiazki"') and o.name = 'FK_AUTORZY _AUTORZY <_KSIAZKI')
alter table "Autorzy <-> Ksiazki"
   drop constraint "FK_AUTORZY _AUTORZY <_KSIAZKI"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"Autorzy <-> Ksiazki"') and o.name = 'FK_AUTORZY _AUTORZY <_AUTORZY')
alter table "Autorzy <-> Ksiazki"
   drop constraint "FK_AUTORZY _AUTORZY <_AUTORZY"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Kary') and o.name = 'FK_KARY_KARY <-> _KLIENCI')
alter table Kary
   drop constraint "FK_KARY_KARY <-> _KLIENCI"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Kary') and o.name = 'FK_KARY_PRACOWNIC_PRACOWNI')
alter table Kary
   drop constraint FK_KARY_PRACOWNIC_PRACOWNI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Klienci') and o.name = 'FK_KLIENCI_KLIENCI <_UZYTKOWN')
alter table Klienci
   drop constraint "FK_KLIENCI_KLIENCI <_UZYTKOWN"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Ksiazki') and o.name = 'FK_KSIAZKI_FORMAT <-_FORMAT')
alter table Ksiazki
   drop constraint "FK_KSIAZKI_FORMAT <-_FORMAT"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Ksiazki') and o.name = 'FK_KSIAZKI_GATUNKI <_GATUNKI')
alter table Ksiazki
   drop constraint "FK_KSIAZKI_GATUNKI <_GATUNKI"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Ksiazki') and o.name = 'FK_KSIAZKI_STATUSY <_STATUSY')
alter table Ksiazki
   drop constraint "FK_KSIAZKI_STATUSY <_STATUSY"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Ksiazki') and o.name = 'FK_KSIAZKI_TLUMACZEN_TLUMACZE')
alter table Ksiazki
   drop constraint FK_KSIAZKI_TLUMACZEN_TLUMACZE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Ksiazki') and o.name = 'FK_KSIAZKI_WYDAWNICT_WYDAWNIC')
alter table Ksiazki
   drop constraint FK_KSIAZKI_WYDAWNICT_WYDAWNIC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Pracownicy') and o.name = 'FK_PRACOWNI_PRACOWNIC_UZYTKOWN')
alter table Pracownicy
   drop constraint FK_PRACOWNI_PRACOWNIC_UZYTKOWN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Rezerwacja') and o.name = 'FK_REZERWAC_REZERWACJ_KLIENCI')
alter table Rezerwacja
   drop constraint FK_REZERWAC_REZERWACJ_KLIENCI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Rezerwacja') and o.name = 'FK_REZERWAC_REZERWACJ_KSIAZKI')
alter table Rezerwacja
   drop constraint FK_REZERWAC_REZERWACJ_KSIAZKI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Uzytkownicy') and o.name = 'FK_UZYTKOWN_KLIENCI <_KLIENCI')
alter table Uzytkownicy
   drop constraint "FK_UZYTKOWN_KLIENCI <_KLIENCI"
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Uzytkownicy') and o.name = 'FK_UZYTKOWN_PRACOWNIC_PRACOWNI')
alter table Uzytkownicy
   drop constraint FK_UZYTKOWN_PRACOWNIC_PRACOWNI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Wypozyczenie') and o.name = 'FK_WYPOZYCZ_WYPOZYCZE_KLIENCI')
alter table Wypozyczenie
   drop constraint FK_WYPOZYCZ_WYPOZYCZE_KLIENCI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('Wypozyczenie') and o.name = 'FK_WYPOZYCZ_WYPOZYCZE_KSIAZKI')
alter table Wypozyczenie
   drop constraint FK_WYPOZYCZ_WYPOZYCZE_KSIAZKI
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Autorzy')
            and   type = 'U')
   drop table Autorzy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"Autorzy <-> Ksiazki"')
            and   name  = 'Autorzy <-> Ksiazki2_FK'
            and   indid > 0
            and   indid < 255)
   drop index "Autorzy <-> Ksiazki"."Autorzy <-> Ksiazki2_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"Autorzy <-> Ksiazki"')
            and   name  = 'Autorzy <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index "Autorzy <-> Ksiazki"."Autorzy <-> Ksiazki_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('"Autorzy <-> Ksiazki"')
            and   type = 'U')
   drop table "Autorzy <-> Ksiazki"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Format')
            and   type = 'U')
   drop table Format
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Gatunki')
            and   type = 'U')
   drop table Gatunki
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Kary')
            and   name  = 'Pracownicy <-> Kary_FK'
            and   indid > 0
            and   indid < 255)
   drop index Kary."Pracownicy <-> Kary_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Kary')
            and   name  = 'Kary <-> Klienci_FK'
            and   indid > 0
            and   indid < 255)
   drop index Kary."Kary <-> Klienci_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Kary')
            and   type = 'U')
   drop table Kary
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Klienci')
            and   name  = 'Klienci <-> Uzytkownicy2_FK'
            and   indid > 0
            and   indid < 255)
   drop index Klienci."Klienci <-> Uzytkownicy2_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Klienci')
            and   type = 'U')
   drop table Klienci
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Ksiazki')
            and   name  = 'Statusy <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Ksiazki."Statusy <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Ksiazki')
            and   name  = 'Gatunki <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Ksiazki."Gatunki <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Ksiazki')
            and   name  = 'Wydawnictwa <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Ksiazki."Wydawnictwa <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Ksiazki')
            and   name  = 'Format <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Ksiazki."Format <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Ksiazki')
            and   name  = 'Tlumaczenia <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Ksiazki."Tlumaczenia <-> Ksiazki_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Ksiazki')
            and   type = 'U')
   drop table Ksiazki
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Pracownicy')
            and   name  = 'Pracownicy <-> Uzytkownicy2_FK'
            and   indid > 0
            and   indid < 255)
   drop index Pracownicy."Pracownicy <-> Uzytkownicy2_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Pracownicy')
            and   type = 'U')
   drop table Pracownicy
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Rezerwacja')
            and   name  = 'Rezerwacja <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Rezerwacja."Rezerwacja <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Rezerwacja')
            and   name  = 'Rezerwacja <-> Klienci_FK'
            and   indid > 0
            and   indid < 255)
   drop index Rezerwacja."Rezerwacja <-> Klienci_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Rezerwacja')
            and   type = 'U')
   drop table Rezerwacja
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Statusy')
            and   type = 'U')
   drop table Statusy
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Tlumaczenia')
            and   type = 'U')
   drop table Tlumaczenia
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Uzytkownicy')
            and   name  = 'Pracownicy <-> Uzytkownicy_FK'
            and   indid > 0
            and   indid < 255)
   drop index Uzytkownicy."Pracownicy <-> Uzytkownicy_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Uzytkownicy')
            and   name  = 'Klienci <-> Uzytkownicy_FK'
            and   indid > 0
            and   indid < 255)
   drop index Uzytkownicy."Klienci <-> Uzytkownicy_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Uzytkownicy')
            and   type = 'U')
   drop table Uzytkownicy
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Wydawnictwa')
            and   type = 'U')
   drop table Wydawnictwa
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Wypozyczenie')
            and   name  = 'Wypozyczenie <-> Ksiazki_FK'
            and   indid > 0
            and   indid < 255)
   drop index Wypozyczenie."Wypozyczenie <-> Ksiazki_FK"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('Wypozyczenie')
            and   name  = 'Wypozyczenie <-> Klienci_FK'
            and   indid > 0
            and   indid < 255)
   drop index Wypozyczenie."Wypozyczenie <-> Klienci_FK"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Wypozyczenie')
            and   type = 'U')
   drop table Wypozyczenie
go

/*==============================================================*/
/* Table: Autorzy                                               */
/*==============================================================*/
create table Autorzy (
   Id_autor             int                  not null,
   Imie_autor           varchar(20)          null,
   Nazwisko_autor       varchar(30)          null,
   constraint PK_AUTORZY primary key nonclustered (Id_autor)
)
go

/*==============================================================*/
/* Table: "Autorzy <-> Ksiazki"                                 */
/*==============================================================*/
create table "Autorzy <-> Ksiazki" (
   Id_ksiazka           int                  not null,
   Id_autor             int                  not null,
   constraint "PK_AUTORZY <-> KSIAZKI" primary key (Id_ksiazka, Id_autor)
)
go

/*==============================================================*/
/* Index: "Autorzy <-> Ksiazki_FK"                              */
/*==============================================================*/
create index "Autorzy <-> Ksiazki_FK" on "Autorzy <-> Ksiazki" (
Id_ksiazka ASC
)
go

/*==============================================================*/
/* Index: "Autorzy <-> Ksiazki2_FK"                             */
/*==============================================================*/
create index "Autorzy <-> Ksiazki2_FK" on "Autorzy <-> Ksiazki" (
Id_autor ASC
)
go

/*==============================================================*/
/* Table: Format                                                */
/*==============================================================*/
create table Format (
   Id_format            int                  not null,
   Nazwa_format         varchar(5)           null,
   constraint PK_FORMAT primary key nonclustered (Id_format)
)
go

/*==============================================================*/
/* Table: Gatunki                                               */
/*==============================================================*/
create table Gatunki (
   Id_gatunek           int                  not null,
   Nazwa_gatunek        varchar(30)          null,
   constraint PK_GATUNKI primary key nonclustered (Id_gatunek)
)
go

/*==============================================================*/
/* Table: Kary                                                  */
/*==============================================================*/
create table Kary (
   Id_kara              int                  not null,
   Id_pracownik         int                  null,
   Id_klient            int                  null,
   Kwota_kara           numeric(3,2)         null,
   Opis_kara            varchar(200)         null,
   Data_kara            datetime             null,
   constraint PK_KARY primary key nonclustered (Id_kara)
)
go

/*==============================================================*/
/* Index: "Kary <-> Klienci_FK"                                 */
/*==============================================================*/
create index "Kary <-> Klienci_FK" on Kary (
Id_klient ASC
)
go

/*==============================================================*/
/* Index: "Pracownicy <-> Kary_FK"                              */
/*==============================================================*/
create index "Pracownicy <-> Kary_FK" on Kary (
Id_pracownik ASC
)
go

/*==============================================================*/
/* Table: Klienci                                               */
/*==============================================================*/
create table Klienci (
   Id_klient            int                  not null,
   Id_uzytkownik        int                  null,
   Legitymacja_klient   int                  null,
   Zablokowany_klient   bit                  null,
   constraint PK_KLIENCI primary key nonclustered (Id_klient)
)
go

/*==============================================================*/
/* Index: "Klienci <-> Uzytkownicy2_FK"                         */
/*==============================================================*/
create index "Klienci <-> Uzytkownicy2_FK" on Klienci (
Id_uzytkownik ASC
)
go

/*==============================================================*/
/* Table: Ksiazki                                               */
/*==============================================================*/
create table Ksiazki (
   Id_ksiazka           int                  not null,
   Id_format            int                  not null,
   Id_tlumaczenie       int                  not null,
   Id_gatunek           int                  not null,
   Id_status            int                  not null,
   Id_wydawnictwo       int                  not null,
   Tytul_ksiazka        varchar(50)          null,
   Numer_ksiazka        varchar(45)          null,
   Wydanie_ksiazka      datetime             null,
   Strony_ksiazka       int                  null,
   Tagi_ksiazka         varchar(500)         null,
   constraint PK_KSIAZKI primary key nonclustered (Id_ksiazka)
)
go

/*==============================================================*/
/* Index: "Tlumaczenia <-> Ksiazki_FK"                          */
/*==============================================================*/
create index "Tlumaczenia <-> Ksiazki_FK" on Ksiazki (
Id_tlumaczenie ASC
)
go

/*==============================================================*/
/* Index: "Format <-> Ksiazki_FK"                               */
/*==============================================================*/
create index "Format <-> Ksiazki_FK" on Ksiazki (
Id_format ASC
)
go

/*==============================================================*/
/* Index: "Wydawnictwa <-> Ksiazki_FK"                          */
/*==============================================================*/
create index "Wydawnictwa <-> Ksiazki_FK" on Ksiazki (
Id_wydawnictwo ASC
)
go

/*==============================================================*/
/* Index: "Gatunki <-> Ksiazki_FK"                              */
/*==============================================================*/
create index "Gatunki <-> Ksiazki_FK" on Ksiazki (
Id_gatunek ASC
)
go

/*==============================================================*/
/* Index: "Statusy <-> Ksiazki_FK"                              */
/*==============================================================*/
create index "Statusy <-> Ksiazki_FK" on Ksiazki (
Id_status ASC
)
go

/*==============================================================*/
/* Table: Pracownicy                                            */
/*==============================================================*/
create table Pracownicy (
   Id_pracownik         int                  not null,
   Id_uzytkownik        int                  null,
   Pesel_pracownik      int                  null,
   Dowod_pracownik      varchar(15)          null,
   Ulica_pracownik      varchar(35)          null,
   Miejscowosc_pracownik varchar(20)          null,
   Kod_pracownik        varchar(6)           null,
   Telefon_pracownik    varchar(12)          null,
   Pensja_pracownik     numeric(4,2)         null,
   constraint PK_PRACOWNICY primary key nonclustered (Id_pracownik)
)
go

/*==============================================================*/
/* Index: "Pracownicy <-> Uzytkownicy2_FK"                      */
/*==============================================================*/
create index "Pracownicy <-> Uzytkownicy2_FK" on Pracownicy (
Id_uzytkownik ASC
)
go

/*==============================================================*/
/* Table: Rezerwacja                                            */
/*==============================================================*/
create table Rezerwacja (
   Id_rezerwacja        int                  not null,
   Id_ksiazka           int                  not null,
   Id_klient            int                  null,
   Data_rezerwacja      datetime             null,
   Koniec_rezerwacja    datetime             null,
   constraint PK_REZERWACJA primary key nonclustered (Id_rezerwacja)
)
go

/*==============================================================*/
/* Index: "Rezerwacja <-> Klienci_FK"                           */
/*==============================================================*/
create index "Rezerwacja <-> Klienci_FK" on Rezerwacja (
Id_klient ASC
)
go

/*==============================================================*/
/* Index: "Rezerwacja <-> Ksiazki_FK"                           */
/*==============================================================*/
create index "Rezerwacja <-> Ksiazki_FK" on Rezerwacja (
Id_ksiazka ASC
)
go

/*==============================================================*/
/* Table: Statusy                                               */
/*==============================================================*/
create table Statusy (
   Id_status            int                  not null,
   Nazwa_status         varchar(20)          null,
   Opis_status          varchar(250)         null,
   constraint PK_STATUSY primary key nonclustered (Id_status)
)
go

/*==============================================================*/
/* Table: Tlumaczenia                                           */
/*==============================================================*/
create table Tlumaczenia (
   Id_tlumaczenie       int                  not null,
   Nazwa_tlumaczenie    varchar(40)          null,
   constraint PK_TLUMACZENIA primary key nonclustered (Id_tlumaczenie)
)
go

/*==============================================================*/
/* Table: Uzytkownicy                                           */
/*==============================================================*/
create table Uzytkownicy (
   Id_uzytkownik        int                  not null,
   Id_pracownik         int                  null,
   Id_klient            int                  null,
   Login_uzytkownik     varchar(20)          not null,
   Haslo_uzytkownik     varchar(30)          not null,
   Rodzaj_uzytkownik    int                  not null,
   Imie_uzytkownik      varchar(20)          null,
   Nazwisko_uzytkownik  varchar(30)          null,
   constraint PK_UZYTKOWNICY primary key nonclustered (Id_uzytkownik)
)
go

/*==============================================================*/
/* Index: "Klienci <-> Uzytkownicy_FK"                          */
/*==============================================================*/
create index "Klienci <-> Uzytkownicy_FK" on Uzytkownicy (
Id_klient ASC
)
go

/*==============================================================*/
/* Index: "Pracownicy <-> Uzytkownicy_FK"                       */
/*==============================================================*/
create index "Pracownicy <-> Uzytkownicy_FK" on Uzytkownicy (
Id_pracownik ASC
)
go

/*==============================================================*/
/* Table: Wydawnictwa                                           */
/*==============================================================*/
create table Wydawnictwa (
   Id_wydawnictwo       int                  not null,
   Nazwa_wydawnictwo    varchar(45)          null,
   constraint PK_WYDAWNICTWA primary key nonclustered (Id_wydawnictwo)
)
go

/*==============================================================*/
/* Table: Wypozyczenie                                          */
/*==============================================================*/
create table Wypozyczenie (
   Id_wypozyczenie      int                  not null,
   Id_ksiazka           int                  not null,
   Id_klient            int                  null,
   Data_wypozyczenie    datetime             null,
   Koniec_wypozyczenie  datetime             null,
   constraint PK_WYPOZYCZENIE primary key nonclustered (Id_wypozyczenie)
)
go

/*==============================================================*/
/* Index: "Wypozyczenie <-> Klienci_FK"                         */
/*==============================================================*/
create index "Wypozyczenie <-> Klienci_FK" on Wypozyczenie (
Id_klient ASC
)
go

/*==============================================================*/
/* Index: "Wypozyczenie <-> Ksiazki_FK"                         */
/*==============================================================*/
create index "Wypozyczenie <-> Ksiazki_FK" on Wypozyczenie (
Id_ksiazka ASC
)
go

alter table "Autorzy <-> Ksiazki"
   add constraint "FK_AUTORZY _AUTORZY <_KSIAZKI" foreign key (Id_ksiazka)
      references Ksiazki (Id_ksiazka)
go

alter table "Autorzy <-> Ksiazki"
   add constraint "FK_AUTORZY _AUTORZY <_AUTORZY" foreign key (Id_autor)
      references Autorzy (Id_autor)
go

alter table Kary
   add constraint "FK_KARY_KARY <-> _KLIENCI" foreign key (Id_klient)
      references Klienci (Id_klient)
go

alter table Kary
   add constraint FK_KARY_PRACOWNIC_PRACOWNI foreign key (Id_pracownik)
      references Pracownicy (Id_pracownik)
go

alter table Klienci
   add constraint "FK_KLIENCI_KLIENCI <_UZYTKOWN" foreign key (Id_uzytkownik)
      references Uzytkownicy (Id_uzytkownik)
go

alter table Ksiazki
   add constraint "FK_KSIAZKI_FORMAT <-_FORMAT" foreign key (Id_format)
      references Format (Id_format)
go

alter table Ksiazki
   add constraint "FK_KSIAZKI_GATUNKI <_GATUNKI" foreign key (Id_gatunek)
      references Gatunki (Id_gatunek)
go

alter table Ksiazki
   add constraint "FK_KSIAZKI_STATUSY <_STATUSY" foreign key (Id_status)
      references Statusy (Id_status)
go

alter table Ksiazki
   add constraint FK_KSIAZKI_TLUMACZEN_TLUMACZE foreign key (Id_tlumaczenie)
      references Tlumaczenia (Id_tlumaczenie)
go

alter table Ksiazki
   add constraint FK_KSIAZKI_WYDAWNICT_WYDAWNIC foreign key (Id_wydawnictwo)
      references Wydawnictwa (Id_wydawnictwo)
go

alter table Pracownicy
   add constraint FK_PRACOWNI_PRACOWNIC_UZYTKOWN foreign key (Id_uzytkownik)
      references Uzytkownicy (Id_uzytkownik)
go

alter table Rezerwacja
   add constraint FK_REZERWAC_REZERWACJ_KLIENCI foreign key (Id_klient)
      references Klienci (Id_klient)
go

alter table Rezerwacja
   add constraint FK_REZERWAC_REZERWACJ_KSIAZKI foreign key (Id_ksiazka)
      references Ksiazki (Id_ksiazka)
go

alter table Uzytkownicy
   add constraint "FK_UZYTKOWN_KLIENCI <_KLIENCI" foreign key (Id_klient)
      references Klienci (Id_klient)
go

alter table Uzytkownicy
   add constraint FK_UZYTKOWN_PRACOWNIC_PRACOWNI foreign key (Id_pracownik)
      references Pracownicy (Id_pracownik)
go

alter table Wypozyczenie
   add constraint FK_WYPOZYCZ_WYPOZYCZE_KLIENCI foreign key (Id_klient)
      references Klienci (Id_klient)
go

alter table Wypozyczenie
   add constraint FK_WYPOZYCZ_WYPOZYCZE_KSIAZKI foreign key (Id_ksiazka)
      references Ksiazki (Id_ksiazka)
go

